using System.Collections;
using UnityEngine;

public class OpticalAIMShower : WeaponInterfaceChanger
{
	private float normalFOV;

	private float zoomedFOV = 15f;

	private TPSCamera cam;

	private Camera camLod;

	private PlayerBehavior pBehavior;

	private bool _sniperMode;

	public bool sniperMode
	{
		get
		{
			return _sniperMode;
		}
		set
		{
			_sniperMode = value;
			playerBehavior.SwitchAimMod(value);
		}
	}

	private void OnEnable()
	{
		StartCoroutine(Check());
	}

	private IEnumerator Check()
	{
		yield return null;
		if (IsMinePlayer())
		{
			StartCoroutine(ShowStart());
		}
		else
		{
			base.enabled = false;
		}
	}

	private IEnumerator ShowStart()
	{
		yield return null;
		cam = GameController.instance.tpsCamera;
		camLod = NGUITools.FindCameraForLayer(28);
		normalFOV = cam.GetComponent<Camera>().fieldOfView;
		OpticalAimHUD.instance.SetActiveModeAim(false);
		OpticalAimHUD.instance.SetActiveButAim(true);
		OpticalAimHUD.instance.stateOpticalActive = true;
		playerBehavior.opticalAimer = this;
	}

	private void OnDisable()
	{
		if (!IsMinePlayer())
		{
			return;
		}
		HideSniperAimer();
		if (cam != null)
		{
			if (camLod != null)
			{
				camLod.fieldOfView = normalFOV;
			}
			cam.GetComponent<Camera>().fieldOfView = normalFOV;
		}
		if (OpticalAimHUD.instance != null)
		{
			OpticalAimHUD.instance.SetActiveModeAim(false);
			OpticalAimHUD.instance.SetActiveButAim(false);
			OpticalAimHUD.instance.stateOpticalActive = false;
		}
		if (playerBehavior != null)
		{
			playerBehavior.opticalAimer = null;
		}
	}

	private void SwitchRenderers(bool on)
	{
		playerBehavior.SetVisibleOnlyMeshObjPlayer(on);
	}

	public void ShowSniperAimer()
	{
		sniperMode = true;
		SwitchRenderers(false);
		base.transform.localPosition = base.transform.forward * -3f;
		cam.GetComponent<Camera>().fieldOfView = zoomedFOV;
		if (camLod != null)
		{
			camLod.fieldOfView = zoomedFOV;
		}
		WalkWindow.instance.opticalAimHUD.SetActiveModeAim(true);
		SwitchRenderers(false);
	}

	public void HideSniperAimer()
	{
		sniperMode = false;
		SwitchRenderers(true);
		if (cam != null)
		{
			cam.GetComponent<Camera>().fieldOfView = normalFOV;
			if (camLod != null)
			{
				camLod.fieldOfView = normalFOV;
			}
		}
		if (WalkWindow.instance != null)
		{
			WalkWindow.instance.opticalAimHUD.SetActiveModeAim(false);
		}
		base.transform.localPosition = Vector3.zero;
	}
}
